package com.hearwego;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import com.utilities.HWGSQLiteHelper;
import com.utilities.Informacion;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


public class TabFragmentHeaderDetalle extends Fragment {
	
	ImageView imagen_header;
	ProgressDialog dialog;
	List<Informacion> informacion;
	Drawable d;
	View view;
	HWGSQLiteHelper usdbh;
	SQLiteDatabase db;
	byte[] bitmap_foto;
	Bitmap bm = null;
	byte[] bb;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.activity_tab_fragment_header_detalle, container, false);
		
		new LoagGastos().execute("");
		return view;
	}

	
	public class LoagGastos extends AsyncTask<String, String, String>{
    	int zeroGastos = -1;
    	
    	@Override
    		protected void onPreExecute() {
    			super.onPreExecute();
    		}
    	
		@Override
		protected String doInBackground(String... params) {
			usdbh =new HWGSQLiteHelper(getActivity(), "DBHWG", null, 1);
	        db = usdbh.getWritableDatabase();

	        if(db != null)
	        {
	        	Cursor c = db.rawQuery("SELECT * FROM Detalle", null);
	        	if (c.moveToFirst()) {
	        		
					if(c.getBlob(c.getColumnIndexOrThrow("bitmapfoto"))!= null){
						bb = c.getBlob(c.getColumnIndexOrThrow("bitmapfoto"));
						Log.i("BLOB", ""+bb);
					}
	        		
//					Bitmap scaledBm = Bitmap.createScaledBitmap(bm, 80, 80, true);
//	        		ByteArrayOutputStream stream = new ByteArrayOutputStream();
//					scaledBm.compress(Bitmap.CompressFormat.PNG, 50, stream);
//					byte[] byteArray = stream.toByteArray();
	        	}else{
	        		zeroGastos = 0;
	        	}
	        	db.close();
	        }
			return null;
		}
		
		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
//			imagen_header = (ImageView) view.findViewById(R.id.imagen_poi_detalle);
//			imagen_header.setImageBitmap(BitmapFactory.decodeByteArray(bb, 0, bb.length));


//			Toast.makeText(getActivity().getApplicationContext(), "Datos traidos de BD", Toast.LENGTH_SHORT).show();
//			dialog1.dismiss();
		}
    	
    }
}
